﻿using System;
using System.Drawing;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using BolsaTalentos.DataContextClasses;

namespace BolsaTalentos.BLL
{
    public class Carrera
    {
        //Campos
        private int id;
        private string descripcion;

        //Propiedades
        public int ID
        {
            get { return this.id; }
        }
        public string Descripcion
        {
            get { return this.descripcion; }
            set { this.descripcion = value; }
        }

        //Constructores
        public Carrera(int IDToSearch)
        {
            try
            {
                DataClassesDataContext DB = new DataClassesDataContext();

                DataContextClasses.Carrera Car = (from c in DB.Carreras
                                                  where c.ID == IDToSearch
                                                  select c).First();

                this.id = Car.ID;
                this.descripcion = Car.Descripcion;
            }
            catch (SqlException SqlEx)
            {
                throw new Exception("No existe tal carrera\n" + SqlEx.Message);
            }
        }

        //Metodos
        public static Carrera GetCarreraByUsuarioEgresadoID(int UsuarioEgresadoID)
        {
            try
            {
                DataClassesDataContext DB = new DataClassesDataContext();

                DataContextClasses.Egresado Egr = (from e in DB.Egresados
                                                   where e.ID == UsuarioEgresadoID
                                                   select e).First();

                return new Carrera(Egr.ID_Carrera);
            }
            catch (SqlException SqlEx)
            {
                throw new Exception("Hubo un problema con la base de datos\n" + SqlEx.Message);
            }
        }
        public static Carrera GetCarreraByVacanteID(int VacanteID)
        {
            DataClassesDataContext DB = new DataClassesDataContext();

            DataContextClasses.Vacante Vac = (from v in DB.Vacantes
                                              where v.ID == VacanteID
                                              select v).First();

            Carrera Carrera = new Carrera(Vac.ID_Carrera);
            return Carrera;
        }
    }
}
